package com.hui.demo.service.impl;

import com.hui.demo.model.Mood;
import com.hui.demo.producer.MoodProducer;
import com.hui.demo.repository.MoodRepository;
import com.hui.demo.service.MoodService;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.Destination;

/**
 * 说说服务接口实现类
 * @author ziv
 * @date 2018-12-24
 */
@Service
public class MoodServiceImpl implements MoodService {

    /**
     * 创建队列
     */
    private static Destination destination = new ActiveMQQueue("ziv.queue.asyn.save");

    @Resource
    private MoodRepository moodRepository;

    @Resource
    private MoodProducer moodProducer;

    @Override
    public Mood save(Mood mood) {
        return moodRepository.save(mood);
    }

    @Override
    public String asynSave(Mood mood) {
        moodProducer.sendMessage(destination, mood);
        return "success";
    }
}
